﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace DeepSeekDemo
{
    public class EssayScoringService
    {
        public void Test()
        {
            // 使用示例
            //var service = new EssayScoringService();
            //await service.ScoreEssayAsync("这里是需要评分的作文内容...");
        }

        //private const string API_KEY = "your_api_key_here";
        private const string API_KEY = "sk-b02eda3a6fc94032a9626427d0c1a4e0";   // 作文打分
        private const string API_ENDPOINT = "https://api.deepseek.com/v1";

        private static readonly HttpClient _httpClient = new HttpClient();

        public async Task ScoreEssayAsync(string essayContent)
        {
            try
            {
                // 构造请求体
                var requestData = new
                {
                    text = essayContent,
                    criteria = new[] { "内容完整性", "语言表达", "逻辑性", "思想深度", "创意性" }
                };

                // 设置请求头
                _httpClient.DefaultRequestHeaders.Authorization =
                    new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", API_KEY);

                // 发送POST请求
                var response = await _httpClient.PostAsync(
                    API_ENDPOINT,
                    new StringContent(
                        JsonConvert.SerializeObject(requestData),
                        Encoding.UTF8,
                        "application/json")
                    );

                // 处理响应
                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();
                    var result = JsonConvert.DeserializeObject<ScoringResult>(responseContent);
                    var score = result.TotalScore;
                }
                else
                {
                    string data = "API调用失败，状态码：{response.StatusCode}";
                }
            }
            catch (Exception ex)
            {
            }
        }

        // 响应模型示例（需根据实际API文档调整）
        public class ScoringResult
        {
            public int TotalScore { get; set; }
            public CriteriaScore[] CriteriaScores { get; set; }
        }

        public class CriteriaScore
        {
            public string Criterion { get; set; }
            public int Score { get; set; }
            public string Comment { get; set; }
        }
    }

}


